Skip to content

Match the Content-Type header name case-insensitively - #3725

Merged
velo merged 1 commit into
OpenFeign:masterfrom
spor3006:fix/content-type-case-insensitive
Nov 30, 2026
Merged

velo merged 1 commit into
OpenFeign:masterfrom
spor3006:fix/content-type-case-insensitive

Conversation

@spor3006

Copy link
Copy Markdown
Contributor

Header names are case-insensitive, but the two places that treat Content-Type specially compare the name with equals("Content-Type").

RequestTemplate replaces Content-Type instead of appending to it, so a request carries a single type (#1219). When the header is set as content-type, for example from a RequestInterceptor on a method annotated with Content-Type: application/json, it is appended instead, and DefaultClient sends two Content-Type headers.

GoogleHttpClient skips Content-Type when it copies headers, because ByteArrayContent already sends it (#1737). A content-type header was copied as well, so it went out twice. If the request was built with a case-sensitive header map (Request.create with a HashMap), the body was also typed application/octet-stream next to the caller's value.

Both checks now use equalsIgnoreCase, and GoogleHttpClient looks the body type up the same way instead of headers().get("Content-Type"). Nothing changes for the canonical spelling.

Tests: RequestTemplateTest covers three spellings, FeignBuilderTest checks the interceptor case end to end against MockWebServer, and GoogleHttpClientTest covers both the duplicate header and the case-sensitive map. All of them failed before the change. mvn -Pdev verify passes for core, googlehttpclient, okhttp, hc5, httpclient, jaxrs2 and spring.

Header names are case-insensitive, but two places that special-case
Content-Type compared the name with equals("Content-Type"):

* RequestTemplate replaces Content-Type instead of appending to it, so
  a request ends up with a single type (OpenFeign#1219). Setting it as
  `content-type`, e.g. from a RequestInterceptor on a method annotated
  with `Content-Type: application/json`, appended instead, and the
  request went out with two Content-Type headers.
* GoogleHttpClient skips Content-Type when copying headers, because
  ByteArrayContent already sends it (OpenFeign#1737). A `content-type` header was
  copied as well, so it was sent twice. When the request's header map
  is case-sensitive (Request.create with a HashMap), the body was also
  typed application/octet-stream next to the caller's value.

Both checks now use equalsIgnoreCase.

Signed-off-by: Sparshal Kothari <41056517+spor3006@users.noreply.github.com>
@velo
velo merged commit 2886eb0 into OpenFeign:master Nov 30, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants